home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Armageddon.lua < prev    next >
Text File  |  2010-09-27  |  5KB  |  132 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Armageddon + Projectile Comet
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.armageddon={}
  10. cc.armageddon.comet={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.armageddon.gfx_icon=loadgfx("weapons/armageddonicon.png")            -- Weapon Icon
  14. setmidhandle(cc.armageddon.gfx_icon)
  15. cc.armageddon.gfx_pro=loadgfx("weapons/comet.bmp")                        -- Projectile Image
  16. setmidhandle(cc.armageddon.gfx_pro)
  17. cc.armageddon.sfx_waterimpact=loadsfx("firefragment.wav")
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: Armageddon
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.armageddon.id=addweapon("cc.armageddon","Armageddon",cc.armageddon.gfx_icon,0,3)    -- Add Weapon (0 uses, first in round 3)
  24.  
  25. function cc.armageddon.draw()                                            -- Draw
  26.     -- Fade Dark
  27.     if weapon_shots>0 and weapon_timer<0.4 then
  28.         weapon_timer=weapon_timer+0.01
  29.     end
  30. end
  31.  
  32. function cc.armageddon.attack(attack)                                    -- Attack
  33.     if (weapon_shots<=0) and (attack==1) then
  34.         -- No more weapon switching!
  35.         useweapon(0)
  36.         weapon_shots=weapon_shots+1
  37.         -- Random Seed
  38.         randomseed(getframe()*123+getround()*98)
  39.         -- Spawn Comets (amount depending on map size)
  40.         limit=math.ceil(getmapwidth()/100)*math.ceil(getmapheight()/150)
  41.         if limit>100 then
  42.             limit=100
  43.         end
  44.         for i=1,limit,1 do
  45.             pid=createprojectile(cc.armageddon.comet.id)
  46.             projectiles[pid]={}
  47.             projectiles[pid].x=random(40,getmapwidth()-40)
  48.             projectiles[pid].y=-random(500,650)
  49.             projectiles[pid].sx=random(-15,15)*0.1
  50.             projectiles[pid].sy=random(150,200)*0.1
  51.             projectiles[pid].timer=i*random(15,20)
  52.         end
  53.         -- End Turn
  54.         endturn()
  55.     end
  56. end
  57.  
  58. --------------------------------------------------------------------------------
  59. -- Projectile: comet
  60. --------------------------------------------------------------------------------
  61.  
  62. cc.armageddon.comet.id=addprojectile("cc.armageddon.comet")        -- Add Projectile
  63.  
  64. function cc.armageddon.comet.draw(id)                            -- Draw
  65.     setbgcolor(0,0,0,weapon_timer,0.01)
  66.     if projectiles[id].timer<=0 then
  67.         -- Fire
  68.         setblend(blend_light)
  69.         setalpha(math.random(1,7)*0.1)
  70.         setcolor(255,255,255)
  71.         setscale(1,1)
  72.         setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))+180)
  73.         drawimage(gfx_fire,projectiles[id].x,projectiles[id].y)
  74.         -- Comet
  75.         setblend(blend_alpha)
  76.         setalpha(1)
  77.         setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  78.         drawimage(cc.armageddon.gfx_pro,projectiles[id].x,projectiles[id].y)
  79.     end
  80. end
  81.  
  82. function cc.armageddon.comet.update(id)                            -- Update
  83.     -- Timer
  84.     if projectiles[id].timer>0 then
  85.         -- Count Down before comet appears
  86.         projectiles[id].timer=projectiles[id].timer-1
  87.     else
  88.         -- Commet appears
  89.         rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  90.         -- Particle Tail
  91.         particle(p_smoke,projectiles[id].x+math.random(-6,6),projectiles[id].y-7)
  92.         particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  93.         particlefadealpha(0.05)
  94.         particle(p_lightpuff,projectiles[id].x+math.random(-5,5),projectiles[id].y-5)
  95.         particlefadealpha(0.04)
  96.         -- Move (in substep loop for optimal collision precision)
  97.         msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/10)
  98.         msubx=projectiles[id].sx/msubt
  99.         msuby=projectiles[id].sy/msubt
  100.         for i=1,msubt,1 do
  101.             projectiles[id].x=projectiles[id].x+msubx
  102.             projectiles[id].y=projectiles[id].y+msuby
  103.             -- Collision
  104.             if collision(cc.armageddon.gfx_pro,projectiles[id].x,projectiles[id].y)==1 then
  105.                 -- Cause damage
  106.                 arealdamage(projectiles[id].x,projectiles[id].y,155,45)
  107.                 -- Destroy terrain
  108.                 terrainexplosion(projectiles[id].x,projectiles[id].y,60,1)
  109.                 -- Crater
  110.                 grey=math.random(0,40)
  111.                 if math.random(0,1)==1 then
  112.                     terrainalphaimage(gfx_crater175,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  113.                 else
  114.                     terrainalphaimage(gfx_crater200,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  115.                 end
  116.                 -- Free projectile
  117.                 freeprojectile(id)
  118.                 break
  119.             end
  120.             -- Water
  121.             if (projectiles[id].y)>getwatery()+5 then
  122.                 -- Effects
  123.                 particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  124.                 particlesize(1.5,2.0)
  125.                 playsound(cc.armageddon.sfx_waterimpact)
  126.                 -- Free projectile
  127.                 freeprojectile(id)
  128.                 break
  129.             end
  130.         end
  131.     end
  132. end